package com.gitee.wsl.collections.set


/**
 * Implements `MultiSet`, using a [HashMap] to provide the
 * data storage. This is the standard implementation of a multiset.
 *
 *
 * A `MultiSet` stores each object in the collection together with a
 * count of occurrences. Extra methods on the interface allow multiple copies
 * of an object to be added or removed at once.
 *
 *
 * @param <E> the type held in the multiset
 * @since 4.1
</E> */
class HashMultiSet<E>() : AbstractMapMultiSet<E>(HashMap()){
    /**
     * Constructs a multiset containing all the members of the given collection.
     *
     * @param coll  a collection to copy into this multiset
     */
    constructor(coll: Collection<E>) : this() {
        if(coll.isNotEmpty())
           addAll(coll)
    }

    constructor(coll: Array<E>) : this() {
        if(coll.isNotEmpty())
          addAll(coll)
    }

    /**
     * Deserializes the multiset in using a custom routine.
     *
     * @param in the input stream
     * @throws IOException if an error occurs while reading from the stream
     * @throws ClassNotFoundException if an object read from the stream cannot be loaded
     */
//    @Throws(IOException::class, java.lang.ClassNotFoundException::class)
//    private fun readObject(`in`: ObjectInputStream) {
//        `in`.defaultReadObject()
//        setMap(HashMap())
//        super.doReadObject(`in`)
//    }

    /**
     * Serializes this object to an ObjectOutputStream.
     *
     * @param out the target ObjectOutputStream.
     * @throws IOException thrown when an I/O errors occur writing to the target stream.
     */
//    @Throws(IOException::class)
//    private fun writeObject(out: ObjectOutputStream) {
//        out.defaultWriteObject()
//        super.doWriteObject(out)
//    }
}

fun<E> Sets.newHashMultiSet(vararg element: E) = HashMultiSet(element)

